<?php
namespace Admin\Controller;
use Think\Controller;

class ConfigureController extends HomeController {
	/*
	* Function:		contractTempleteList
	* Description:	合同模板管理-列表
	*/
    public function contractTempleteList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter = returnFilter($filter);
		$list = D('ContractTemplete')->getContractTempleteList($page,$filter,$pageSize);
		$count =  D('ContractTemplete')->getContractTempleteCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addContractTemplete
	* Description:	添加合同模板管理
	*/
	public function addContractTemplete(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			if(empty($data['attachment'])){
				$ret = array('code'=>0,'message'=>'请上传合同文件!');
				$this->ajaxReturn($ret);
			}
			if(D('ContractTemplete')->addContractTemplete($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editContractTemplete
	* Description:	编辑合同模板管理
	* @param:		$id int id
	*/
	public function editContractTemplete($id = ''){
		if(IS_POST){
			$data = I('post.');
			if(empty($data['attachment'])){
				$ret = array('code'=>0,'message'=>'请上传合同文件!');
				$this->ajaxReturn($ret);
			}
			if(D('ContractTemplete')->updateContractTemplete($data)){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$contractTempleteInfo = D('ContractTemplete')->getContractTempleteInfo($id);
				$this->assign('contractTempleteInfo',$contractTempleteInfo);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		contractTempleteDetail
	* Description:	合同模板详情
	* @param:		$id int id
	*/
	public function contractTempleteDetail($id = ''){
		$this->display();
	}
	
	/*
	* Function:		systemLogsList
	* Description:	操作记录
	*/
    public function systemLogsList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter = returnFilter($filter);
		$list = D('SystemLogs')->getSystemLogsList($page,$filter,$pageSize);
		$count =  D('SystemLogs')->getSystemLogsCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addressList
	* Description:	地址列表
	*/
	public function addressList(){
		$filter = I('post.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter['status'] = 1;
		$addressList = D('Regions')->getAddressList($page,$filter,$pageSize);
		$count =  D('Regions')->getAddressCount($filter);
		$pages = getpage($count,$pageSize);
		$show = $pages->show();
		$this->assign('addressList',$addressList);
		$this->assign('filter',$filter);
		$this->assign('page',$show);
		$this->display();
    }
	
	/*
	* Function:		addAddress
	* Description:	添加地址
	*/
	public function addAddress(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			$lastRegionId = D('Regions')->getRegionIdDesc();
			$data['region_path'] = ',3133,3182,'.($lastRegionId+1).',';
			if(D('Regions')->addAddress($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editAddress
	* Description:	编辑地址
	* @param:		$id int id
	*/
	public function editAddress($id = ''){
		if(IS_POST){
			$data = I('post.');
			if(D('Regions')->editAddress($data)){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$regionsInfo = D('Regions')->getAddressInfo($id);
				$this->assign('regionsInfo',$regionsInfo);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		departmentList
	* Description:	部门列表
	*/
    public function departmentList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter = returnFilter($filter);
		$list = D('Department')->getDepartmentList($page,$filter,$pageSize);
		$count =  D('Department')->getDepartmentCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addDepartment
	* Description:	添加部门
	*/
	public function addDepartment(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			if(D('Department')->addDepartment($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editDepartment
	* Description:	编辑部门
	* @param:		$id int id
	*/
	public function editDepartment($id = ''){
		if(IS_POST){
			$data = I('post.');
			if(D('Department')->updateDepartment($data)){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$info = D('Department')->getDepartmentInfo($id);
				$this->assign('info',$info);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		deliveryList
	* Description:	快递列表
	*/
    public function deliveryList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter = returnFilter($filter);
		$list = D('Delivery')->getDeliveryList($page,$filter,$pageSize);
		$count =  D('Delivery')->getDeliveryCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addDepartment
	* Description:	添加快递
	*/
	public function addDelivery(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			if(D('Delivery')->addDelivery($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editDelivery
	* Description:	编辑快递
	* @param:		$id int id
	*/
	public function editDelivery($id = ''){
		if(IS_POST){
			$data = I('post.');
			if(D('Delivery')->updateDelivery($data)){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$info = D('Delivery')->getDeliveryInfo($id);
				$this->assign('info',$info);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		systemPicList
	* Description:	首页图片列表
	*/
    public function systemPicList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter['type'] = 1;
		$filter = returnFilter($filter);
		$list = D('SystemPic')->getSystemPicList($page,$filter,$pageSize);
		$count =  D('SystemPic')->getSystemPicCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addSystemPic
	* Description:	添加首页图片
	*/
	public function addSystemPic(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			$data['addtime'] = date('Y-m-d H:i:s',time());
			if(D('SystemPic')->addSystemPic($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editSystemPic
	* Description:	编辑首页图片
	* @param:		$id int id
	*/
	public function editSystemPic($id = ''){
		if(IS_POST){
			$data = I('post.');
			$ret = D('SystemPic')->updateSystemPic($data);
			if($ret!==false){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$info = D('SystemPic')->getSystemPicInfo($id);
				$this->assign('info',$info);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		deleteSystemPic
	* Description:	删除系统图片
	* @param:		$id
	*/
	public function deleteSystemPic($id = ''){
		if(M('system_pic')->where(['id'=>$id])->delete()){
			$ret = array('code'=>1,'message'=>'操作成功');
			$this->ajaxReturn($ret);
		}else{
			$ret = array('code'=>0,'message'=>'操作失败!');
			$this->ajaxReturn($ret);
		}
	}
	
	/*
	* Function:		otherPicList
	* Description:	首页其他图片列表
	*/
    public function otherPicList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter['type'] = 2;
		$filter = returnFilter($filter);
		$list = D('SystemPic')->getSystemPicList($page,$filter,$pageSize);
		$count =  D('SystemPic')->getSystemPicCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addOtherPic
	* Description:	添加首页其他图片
	*/
	public function addOtherPic(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			$data['addtime'] = date('Y-m-d H:i:s',time());
			if(D('SystemPic')->addSystemPic($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editOtherPic
	* Description:	编辑首页其他图片
	* @param:		$id int id
	*/
	public function editOtherPic($id = ''){
		if(IS_POST){
			$data = I('post.');
			$ret = D('SystemPic')->updateSystemPic($data);
			if($ret!==false){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$info = D('SystemPic')->getSystemPicInfo($id);
				$this->assign('info',$info);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		deleteOtherPic
	* Description:	删除首页其他图片
	* @param:		$id
	*/
	public function deleteOtherPic($id = ''){
		if(M('system_pic')->where(['id'=>$id])->delete()){
			$ret = array('code'=>1,'message'=>'操作成功');
			$this->ajaxReturn($ret);
		}else{
			$ret = array('code'=>0,'message'=>'操作失败!');
			$this->ajaxReturn($ret);
		}
	}
	
	/*
	* Function:		policy
	* Description:	隐私政策
	* @param:		$id int id
	*/
    public function policy(){
		if(IS_POST){
			$data = I('post.');
			$data['value'] = stripslashes(htmlspecialchars_decode($data['value']));
			$ret = D('SystemConfig')->updateSystemConfig($data);
			if($ret!==false){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$info = D('SystemConfig')->getSystemConfigInfoByCode('policy');
			$this->assign('info',$info);
			$this->display();
		}
    }

    /*
	* Function:		agreement
	* Description:	服务协议
	* @param:		$id int id
	*/
    public function agreement(){
		if(IS_POST){
			$data = I('post.');
			$data['value'] = stripslashes(htmlspecialchars_decode($data['value']));
			$ret = D('SystemConfig')->updateSystemConfig($data);
			if($ret!==false){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$info = D('SystemConfig')->getSystemConfigInfoByCode('agreement');
			$this->assign('info',$info);
			$this->display();
		}
    }
}